/**
 *
 */
package edu.hunau.cxb18.spring.life;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 目标对象
 *
 * @author hb
 *
 *         2018年4月16日 下午5:08:07
 */
public class TargetObj implements BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private String att;

    public TargetObj() {
        System.out.println("1-调用无参数构造器实例化对象....");
    }

    public void targetMethod() {
        System.out.println("9-TargetObj目标方法...业务逻辑的执行");
    }

    public Object getAtt() {
        System.out.println("属性的getter方法...");
        return att;
    }

    public void setAtt(String att) {
        System.out.println("2-属性的setter方法...");
        this.att = att;
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("3-BeanNameAware#setBeanName()" + name);

    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("4-ApplicationContextAware#setApplicationContext");

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("6-InitializingBean#afterPropertiesSet...");

    }

    // 配置文件中进行声明
    public void init() {
        System.out.println("7-TargetObj#init -自定义的初始化的方法");
    }

    public void doDestory() {
        System.out.println("11-TargetObj#doDestory -自定义的释放资源的方法");
    }

    /*
     * (non-Javadoc)
     *
     * @see org.springframework.beans.factory.DisposableBean#destroy()
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("10-DisposableBean#destroy方法,释放资源....");

    }

}
